Product Code Database
Example Keywords: trousers -android $9
   » » Wiki: Unary Operation
Tag Wiki 'Unary Operation'.
Tag

In , a unary operation is an operation with only one , i.e. a single input. This is in contrast to , which use two operands. An example is any function , where is a set; the function is a unary operation on .

Common notations are (e.g. ¬, −), (e.g. ), functional notation (e.g. or ), and (e.g. ). Other notations exist as well, for example, in the case of the , a horizontal bar extending the square root sign over the argument can indicate the extent of the argument.


Examples

Absolute value
Obtaining the of a number is a unary operation. This function is defined as |n| = \begin{cases} n, & \mbox{if } n\geq0 \\ -n, & \mbox{if } n<0 \end{cases} where |n| is the absolute value of n.


Negation
Negation is used to find the negative value of a single number. Here are some examples:

-(3) = -3

-( -3) = 3


Factorial
For any positive integer n, the product of the integers less than or equal to n is a unary operation called . In the context of , the is a unary operation extension of factorial.


Trigonometry
In , the trigonometric functions, such as \sin, \cos, and \tan, can be seen as unary operations. This is because it is possible to provide only one term as input for these functions and retrieve a result. By contrast, binary operations, such as , require two different terms to compute a result.


Examples from programming languages
Below is a table summarizing common unary operators along with their symbols, description, and examples:

++
x = 2; ++x; // x is now 3
--
y = 10; --y; // y is now 9
+
a = -5; b = +a; // b is -5


JavaScript
In , these operators are unary:
  • Increment: -, c = 4; d = -c; // d is -4
  • Decrement: !, flag = true; result = !flag; // result is false
  • Positive: ~
  • Negative: num = 5; result = ~num; // result is -6
  • Ones' complement: ++<span style="color:gray;">x</span>
  • : <span style="color:gray;">x</span>++


C family of languages
In the C family of languages, the following operators are unary:

  • Increment: --<span style="color:gray;">x</span>, <span style="color:gray;">x</span>--
  • Decrement: +<span style="color:gray;">x</span>, -<span style="color:gray;">x</span>
  • Address: ~<span style="color:gray;">x</span>
  • : !<span style="color:gray;">x</span>
  • Positive: ++<span style="color:gray;">x</span>
  • Negative: <span style="color:gray;">x</span>++
  • Ones' complement: --<span style="color:gray;">x</span>
  • : <span style="color:gray;">x</span>--
  • : &<span style="color:gray;">x</span>
  • : *<span style="color:gray;">x</span>


Unix shell (Bash)
In the (Bash/), e.g., the following operators are unary:
  • Pre and Post-Increment: +<span style="color:gray;">x</span>, -<span style="color:gray;">x</span>
  • Pre and Post-Decrement: ~<span style="color:gray;">x</span>, !<span style="color:gray;">x</span>
  • Positive: sizeof <span style="color:gray;">x</span>, sizeof(<span style="color:gray;">type-name</span>)
  • Negative: (''type-name'') ''<span style="color:gray;">cast-expression</span>''
  • Logical negation: ++<span style="color:gray;">$x</span>
  • Simple expansion: <span style="color:gray;">$x</span>++
  • Complex expansion: --<span style="color:gray;">$x</span>


PowerShell
In the , the following operators are unary:
  • Increment: <span style="color:gray;">$x</span>--, +<span style="color:gray;">$x</span>
  • Decrement: -<span style="color:gray;">$x</span>, !<span style="color:gray;">$x</span>
  • Positive: $<span style="color:gray;">x</span>
  • Negative: ${#<span style="color:gray;">x</span>}
  • Logical negation: ++<span style="color:gray;">$x</span>
  • Invoke in current scope: <span style="color:gray;">$x</span>++
  • Invoke in new scope: --<span style="color:gray;">$x</span>
  • Cast: <span style="color:gray;">$x</span>--
  • Cast: +<span style="color:gray;">$x</span>
  • Array: -<span style="color:gray;">$x</span>


See also


External links
Page 1 of 1
1
Page 1 of 1
1

Account

Social:
Pages:  ..   .. 
Items:  .. 

Navigation

General: Atom Feed Atom Feed  .. 
Help:  ..   .. 
Category:  ..   .. 
Media:  ..   .. 
Posts:  ..   ..   .. 

Statistics

Page:  .. 
Summary:  .. 
1 Tags
10/10 Page Rank
5 Page Refs